//加载当前日期
function loadDate() {
    var time = new Date();
    var myYear = time.getFullYear();
    var myMonth = time.getMonth() + 1;
    var myDay = time.getDate();
    if (myMonth < 10) {
        myMonth = "0" + myMonth;
    }
    document.getElementById("day_day").innerHTML = myYear + "." + myMonth + "." + myDay;
}
/**
 * 隐藏或者显示侧边栏
 *
 **/
function switchSysBar(flag) {
    var side = $('#side');
    var left_menu_cnt = $('#left_menu_cnt');
    if (flag == true) {	// flag==true
        left_menu_cnt.show(500, 'linear');
        side.css({width: '280px'});
        $('#top_nav').css({width: '77%', left: '304px'});
        $('#main').css({left: '280px'});
    } else {
        if (left_menu_cnt.is(":visible")) {
            left_menu_cnt.hide(10, 'linear');
            side.css({width: '60px'});
            $('#top_nav').css({width: '100%', left: '60px', 'padding-left': '28px'});
            $('#main').css({left: '60px'});
            $("#show_hide_btn").find('img').attr('src', 'images/common/nav_show.png');
        } else {
            left_menu_cnt.show(500, 'linear');
            side.css({width: '280px'});
            $('#top_nav').css({width: '77%', left: '304px', 'padding-left': '0px'});
            $('#main').css({left: '280px'});
            $("#show_hide_btn").find('img').attr('src', 'images/common/nav_hide.png');
        }
    }
}

$(function () {
    var setting = {
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: function (event, treeId, treeNode) {
                //获取到当前点击的节点数据
                // console.log(treeNode);
                //修改iframe的src属性的值
                $("#rightMain").prop("src", treeNode.controller);
                var locationText = "当前位置：系统&nbsp;>&nbsp;业务模块";
                $("#here_area").html(locationText + " > " + treeNode.name);
            }
        },
        async: {
            enable: true,//开启异步加载
            url: "/systemMenu/loadMenuByParentSn",
            //在当前节点找sn
            autoParam: ["sn=parentSn"]
        }
    };
    /*    var setting = {
     async: {
     enable: true,
     url: "http://host/getNode.php",
     autoParam: ["id"]
     }
     };
     假设 异步加载 父节点(node = {id:1, name:"test"}) 的子节点时，将提交参数 id=1
     autoParam: ["id=zId"]
     假设 对父节点 node = {id:1, name:"test"}，进行异步加载时，将提交参数 zId=1*/

    var zNodes = {
        // business: {id: 1, sn: "business", pId: 0, name: "业务模块", isParent: true, open: true},
        // system: {id: 2, sn: "system", pId: 0, name: "系统模块", isParent: true, open: true},
        // charts: {id: 3, sn: "charts", pId: 0, name: "报表模块", isParent: true, open: true}

        business: [
            {id: 1, pId: 0, sn: "business", name: "业务模块", isParent: true, open: true}
            // {id: 11, pId: 1, name: "品牌管理"},
            // {id: 12, pId: 1, name: "供应商管理"},
            // {id: 13, pId: 1, name: "商品供应"},
            // {id: 14, pId: 1, name: "仓库管理"},
            // {id: 14, pId: 1, name: "客户管理"},
            // {id: 14, pId: 1, name: "采购订单管理"},
            // {id: 14, pId: 1, name: "采购入库单管理"},
            // {id: 14, pId: 1, name: "销售出库单管理"}
        ],

        systemManage: [
            {id: 2, pId: 0, sn: "system", name: "系统模块", isParent: true, open: true}
            // {id: 21, pId: 2, name: "部门管理", controller: "/department/list"},
            // {id: 22, pId: 2, name: "员工管理", controller: "/employee/list"},
            // {id: 23, pId: 2, name: "权限管理", controller: "/permission/list"},
            // {id: 24, pId: 2, name: "角色管理", controller: "/role/list"},
            // {id: 24, pId: 2, name: "系统菜单管理", controller: "/systemMenu/list"}
        ],

        charts: [
            {id: 3, pId: 0, sn: "charts", name: "报表模块", isParent: true, open: true}
            // {id: 31, pId: 3, name: "即时库存报表"},
            // {id: 32, pId: 3, name: "订货报表"},
            // {id: 33, pId: 3, name: "销售报表"}
        ]

    };


    $(document).ready(function () {
        $.fn.zTree.init($(".ztree"), setting, zNodes["business"]);
    });


    loadDate();

    // 显示隐藏侧边栏
    $("#show_hide_btn").click(function () {
        switchSysBar();
    });
    var locationText = "当前位置：系统&nbsp;>&nbsp;业务模块";
    //切换菜单项的样式和图标
    $("#TabPage2 li").click(function () {
        //获取当前被点击的元素所在数组中的索引
        var index = $(this).index();
        //先将每个li中的selected的样式删除
        // $("#tabpage2 li").each(
        //     function (index, item) {
        //         $(item).removeclass("selected");
        //         $(item).find("img").prop("src", "images/common/" + (index + 1) + ".jpg");
        //     }
        // )
        $.each($("#TabPage2 li"), function (index, item) {
            $(item).removeClass("selected");
            $(item).find("img").prop("src", "images/common/" + (index + 1) + ".jpg");
        });


        $(this).addClass("selected");

        //为当前li中的img元素设置属性
        $(this).find("img").prop("src", "images/common/" + (index + 1) + "_hover.jpg");

        //切换模块的图片
        $("#nav_module").find("img").prop("src", "images/common/module_" + (index + 1) + ".png");

        //取title的值:例如  业务模块
        text = "当前位置：系统&nbsp;>&nbsp;" + $(this).prop("title");
        //修改当前所在位置的文本
        $("#here_area").html(text);

        //切换菜单的数据
        //获取li中绑定的rootmenu
        var rootMenu = $(this).data("rootmenu");
        $.fn.zTree.init($(".ztree"), setting, zNodes[rootMenu]);
    })
});